package com.itheima.controller;

import com.github.pagehelper.Page;
import com.itheima.entity.PageResult;
import com.itheima.entity.Result;
import com.itheima.pojo.ExceptionLog;
import com.itheima.pojo.SysLog;
import com.itheima.service.ExceptionLogService;
import com.itheima.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName LogController
 * @Description 操作日志控制器
 * @Author pengkaka
 * @Date 2020/8/5 14:35
 * @Version 1.0
 **/

@RestController
@RequestMapping("/log")
@CrossOrigin(allowCredentials="true", allowedHeaders="*", methods={RequestMethod.GET,RequestMethod.POST}, origins="*")
public class LogController {

    @Autowired
    private SysLogService sysLogService;
    
    @Autowired
    private ExceptionLogService exceptionLogService;

    // 获取操作日志列表
    @PostMapping("/getLogList")
    public Result getLogList(@RequestBody Map<String, Object> searchMap) {
        Page<SysLog> pageList = sysLogService.getPageList(searchMap);
        com.itheima.entity.Page result = new com.itheima.entity.Page();
        result.setCurrent((Integer) searchMap.get("currentPage"));
        result.setTotal((int) pageList.getTotal());
        result.setRecords(pageList.getResult());

        return new Result("success", result);
    }


    // 获取系统异常列表
    @PostMapping("/getExceptionList")
    public Result getExceptionList(@RequestBody Map<String, Object> searchMap) {
        Page<ExceptionLog> pageList = exceptionLogService.getPageList(searchMap);
        com.itheima.entity.Page result = new com.itheima.entity.Page();
        result.setCurrent((Integer) searchMap.get("currentPage"));
        result.setTotal((int) pageList.getTotal());
        result.setRecords(pageList.getResult());

        return new Result("success", result);
    }

}
